# -*- coding: utf-8 -*-
# @Time : 2021/2/2 8:39
# @Author : 加钱哥
# @Email : scg@gmail.com
# @File : home_page.py
# @Project : xiangmu

from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
class HomePage():
    def __init__(self,driver):

        self.driver=driver
        self.menu_locator = (By.CSS_SELECTOR,"body > div.container > div.row > div.span3.knowledgecate > div > div.personal-panel > div:nth-child(2) > p:nth-child(4) > a:nth-child(1)")
        self.mission_locator = (By.CSS_SELECTOR, "body > div.container > div.row > div:nth-child(1) > div > a")
        self.export_locator = (By.CSS_SELECTOR, "body > div.container > div.row > div:nth-child(1) > div > div > button")
        self.export1_locator = (By.ID, "excelExport")
        self.ltbody_locator = (By.CSS_SELECTOR, "#form1 > table > tbody")
        self.tr_locator = (By.TAG_NAME, "tr")
        self.td_locator = (By.TAG_NAME, "td")
        self.input_locator = (By.NAME, "task_id[]")
        self.delect_locator = (By.ID, "delete")
        self.close_locator = (By.TAG_NAME, "a")

    def mission(self):
        self.driver.find_element(*self.menu_locator).click()
    def add_mission(self):
        self.driver.find_element(*self.mission_locator).click()
    def home(self):
        self.mission()
        self.add_mission()
    def export(self):
        self.driver.find_element(*self.export_locator).click()
    def export1(self):
        self.driver.find_element(*self.export1_locator).click()
    def assert_true(self):
        self.driver.switch_to.alert.accept()
    def expect_txt(self):
        return self.driver.switch_to.alert.text
    def check(self,content,operation):
        tbody = self.driver.find_element(*self.ltbody_locator)
        trs = tbody.find_elements(*self.tr_locator)
        for tr in trs:
            tds = tr.find_elements(*self.td_locator)
            if tds[4].text == content:
                A = tds[9].find_elements(*self.close_locator)
                for a in A:
                    if a.text ==operation:
                        a.click()
                    self.driver.implicitly_wait(20)
                    return self.driver.current_url
    def get_url(self):
        return self.driver.current_url





